//
//  BSKMenuAlertView.m
//  MicroMemory
//
//  Created by rimi on 16/7/21.
//  Copyright © 2016年 BlueSky. All rights reserved.
//

#import "BSKMenuAlertView.h"
#import "BSKNote.h"
#import "BSKconsts.h"
#import "UIView+SDAutoLayout.h"

@interface BSKMenuAlertView ()

@property(nonatomic,strong) UIView * ContentView;
@property(nonatomic,copy) void(^buttonActionCallBack)(UIButton * sender);
@end

@implementation BSKMenuAlertView

- (instancetype)initWithButtons:(NSArray *)buttons buttonActionCallBack:(void(^)(UIButton * sender))callback
{
	self = [super init];
	if (self) {
		_buttonActionCallBack = callback;
		_buttons = buttons;
		[self initializeUI];
	}
	return self;
}

-(void)initializeUI{
	_ContentView = [[UIView alloc]init];
	_ContentView.center = CGPointMake(ScreenWidth/2, ScreenHeight/2);
	_ContentView.backgroundColor = [UIColor whiteColor];
	_ContentView.layer.cornerRadius = 20;
	CGFloat ContentHeight = 30*_buttons.count+10;
	if (ContentHeight > ScreenHeight * 0.7) {
		ContentHeight = ScreenHeight*0.7;
	}
	_ContentView.bounds = CGRectMake(0, 0, ScreenWidth*0.8, ContentHeight);
	_ContentView.layer.masksToBounds = YES;
	[self addSubview:_ContentView];
	
	for (UIButton * button in _buttons) {
		[self.ContentView addSubview:button];
		NSInteger index =  [_buttons indexOfObject:button];
		[button addTarget:self action:@selector(ButtonsAction:) forControlEvents:UIControlEventTouchUpInside];
		button.sd_layout
		.leftSpaceToView(_ContentView,0)
		.rightSpaceToView(_ContentView,0)
		.heightIs(30)
		.centerYIs(index * 30+20);
	}
}

-(void)ButtonsAction:(UIButton *)sender{
	[self hide];
	if (_buttonActionCallBack) {
		_buttonActionCallBack(sender);
	}
}

@end
